package com.zoweunion.mechanic.service.app.impl;

import com.zoweunion.mechanic.dao.app.ToolCarDataMapper;
import com.zoweunion.mechanic.model.things.ThingsData;
import com.zoweunion.mechanic.service.app.ThingsDataService;
import com.zoweunion.mechanic.service.base.BaseService;
import com.zoweunion.mechanic.util.constants.Constants;
import com.zoweunion.mechanic.util.MyException;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 物联网数据逻辑层
 */
@Service
public class ThingsDataServiceImpl extends BaseService implements ThingsDataService {

    @Autowired
    private ToolCarDataMapper toolCarDataMapper;

    @Override
    public void setPcCarData(ThingsData thingsData) throws MyException {
        if (StringUtils.isBlank(thingsData.getThingsId())) {
            throw new MyException(Constants.CODE_HANDEL_FAILED, "物联网设备没有指定");
        }
        Map<String, Object> pcCar = toolCarDataMapper.getPcCarNew(thingsData.getThingsId(), thingsData.getCId());
        if (pcCar == null || pcCar.get("device_template") == null) {
            throw new MyException(Constants.CODE_HANDEL_FAILED, "此设备尚未配置网关");
        }
        thingsData.setPcCarData(pcCar);
        thingsData.setIntelligentTemplateId(pcCar.get("device_template").toString());
        thingsData.setTableName(thingsData.getTableName());
    }

    @Override
    public void setIntelligentTemplateDetails(ThingsData thingsData) {

    }

    @Override
    public void setFaultCodeTemplateDetails(ThingsData thingsData) {

    }
}
